from EmpVoting import NetworkModifier

class AgentUtilLocalAlg(NetworkModifier):

    def __init__(self, useDynamicFields = False):
        '''
        Constructor
        '''
        self.useDynamicFields = useDynamicFields
        
    def Apply(self, network):
        #Calculate agent utilities for each agent
        for alternative in network.alternativeSet:
            
            for agent in network.agentList:
                
                outEdgesItter = network.graph.out_edges_iter(agent, True)
                agentUtil = 0
                for source, dest, data in outEdgesItter:
                    agentUtil += data["weight"] * dest.intrinsicUtilDict[alternative]
                    
                self.SetAgentDictEntry(agent, "overallUtilDict", alternative, agentUtil)
                